package com.five.calendar.ui.adapter;

import android.support.annotation.LayoutRes;
import android.view.View;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.five.calendar.ApplicationHelper;
import com.five.calendar.R;
import com.missmess.calendarview.CalendarMonth;
import com.missmess.calendarview.YearView;

/**
 * @desc:
 * @auther:duwei
 * @date:2017/9/7
 */

public class YearAdapter extends BaseQuickAdapter <YearAdapter.YearBean,YearAdapter.YearViewHolder>{

    private OnMonthClickCallBack mCallBack;
    public YearAdapter(@LayoutRes int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(YearViewHolder yearViewHolder, YearBean yearBean) {
        yearViewHolder.yearView.setYear(yearBean.getYear());
        yearViewHolder.yearView.setOnMonthClickListener(new YearView.OnMonthClickListener() {
            @Override
            public void onMonthClick(YearView yearView, CalendarMonth calendarMonth) {
//                Toast.makeText(ApplicationHelper.getContext(), calendarMonth.getYear() + "-" + calendarMonth.getMonth(),Toast.LENGTH_SHORT).show();
                if(mCallBack != null){
                    mCallBack.onMonthClick(calendarMonth.getYear(), calendarMonth.getMonth());
                }
            }
        });
    }

    public static class YearViewHolder extends BaseViewHolder{
        YearView yearView;
        public YearViewHolder(View view) {
            super(view);
            yearView = (YearView) view.findViewById(R.id.yv);
        }
    }

    public static class YearBean{
        private int year;

        public int getYear() {
            return year;
        }

        public void setYear(int year) {
            this.year = year;
        }
    }

    public interface OnMonthClickCallBack{
        void onMonthClick(int year, int month);
    }

    public void setMonthClickCallBack(OnMonthClickCallBack callBack){
        this.mCallBack = callBack;
    }

}
